package com.yuncheng.oaApi.busService;

import cn.hutool.core.collection.CollectionUtil;
import com.yuncheng.oaApi.entity.OaProcessBusiness;
import com.yuncheng.oaApi.service.IOaProcessBusinessService;
import org.apache.commons.collections.CollectionUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yuncheng.oaApi.FlowController.NewQyResevvationFlowController;
import com.yuncheng.oaApi.FlowService.NewQyResevvationOaFlowService;
import com.yuncheng.oaApi.constant.OaCommonFlowConstant;
import com.yuncheng.oaApi.entity.QyReservation;
import com.yuncheng.oaApi.entity.QyReservationSxlb;
import com.yuncheng.oaApi.entity.QyReservationZxsxlb;
import com.yuncheng.exception.BusinessException;
import com.yuncheng.oaApi.service.IQyReservationService;
import com.yuncheng.oaApi.service.IQyReservationSxlbService;
import com.yuncheng.oaApi.service.IQyReservationZxsxlbService;
import com.yuncheng.spcyApi.utils.DateConvert;
import com.yuncheng.oaApi.utils.GetUuIdUtils;
import com.yuncheng.oaApi.utils.OaSmsUtils;
import com.yuncheng.vo.HttpResult;
import com.yuncheng.oaApi.vo.Result;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;
import java.text.SimpleDateFormat;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.stream.Collectors;

@Component(value = "QyzxyybService")
public class QyzxyybService {

    // 企业咨询事项管理类别表
    @Resource
    @Lazy
    private IQyReservationZxsxlbService qyReservationZxsxlbService;

    //主表
    @Resource
    @Lazy
    private IQyReservationService qyReservationService;

    //事项类别表
    @Resource
    @Lazy
    private IQyReservationSxlbService qyReservationSxlbService;

    @Resource
    @Lazy
    private NewQyResevvationOaFlowService newQyResevvationFlowService;

    @Resource
    @Lazy
    private NewQyResevvationFlowController newQyResevvationFlowController;

    @Resource
    @Lazy
    private OaSmsUtils oaSmsUtils;

    @Resource
    @Lazy
    private IOaProcessBusinessService oaProcessBusinessService;


    //添加验证码验证
    //根据手机发送短信 ，然后生成验证码，设置有效期，
    public String fsyzm(String fsj) throws NoSuchAlgorithmException, IOException, InvalidKeySpecException, InvocationTargetException, IllegalAccessException {
        //生成验证码
        Random random = new Random();
        int randomNumber = random.nextInt(900000) + 100000; // 生成100000-999999之间的随机数
        String fyzm = String.valueOf(randomNumber);



        String smsZdy = oaSmsUtils.sendSmsZdy(fsj, OaCommonFlowConstant.YZMMSG(fyzm));
        if (smsZdy.contains(OaCommonFlowConstant.SMS_FLAG)){

            Date now = new Date();
            // 计算10分钟后时间
            Date plusTenMinutes = new Date(now.getTime() + 10 * 60 * 1000); // 10分钟转换为毫秒数
            // 创建一个SimpleDateFormat对象，并指定日期和时间的格式
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            // 使用SimpleDateFormat对象的format方法将Date对象转换为字符串
            String fyzmyxq = sdf.format(plusTenMinutes);

            //先根据手机查，有没有未提交的 ,如果没有的话直接生成，如果有的话 更新验证码
            List<QyReservation> qyReservationList = qyReservationService.list(new LambdaQueryWrapper<QyReservation>()
                    .eq(QyReservation::getFsj, fsj).eq(QyReservation::getFtjzt, OaCommonFlowConstant.TJZT_NO));

            if (CollectionUtils.isEmpty(qyReservationList)){
                    this.creatyydj(fsj,fyzm,fyzmyxq);
            }else{
                QyReservation qyReservation = qyReservationList.get(0);
                qyReservation.setFyzm(fyzm);
                qyReservation.setFyzmyxq(fyzmyxq);
                qyReservationService.updateById(qyReservation);
            }

        }else {
            return smsZdy;
        }
        return "发送成功";
    }

    //做一个只创建的 什么都不需要返回
    public Map creatyydj(String fsj,String fyzm,String fyzmyxq) throws InvocationTargetException, IllegalAccessException {

        String qyReservationId = null;

        List<QyReservation> qyReservationList = qyReservationService.list(new LambdaQueryWrapper<QyReservation>()
                .eq(QyReservation::getFsj, fsj).eq(QyReservation::getFtjzt, OaCommonFlowConstant.TJZT_NO));

        QyReservation qyReservation = null;
        List<QyReservationZxsxlb> qyReservationZxsxlbList = null;
        //初始化
        if (CollectionUtils.isEmpty(qyReservationList)){
            qyReservation = new QyReservation();
            qyReservationId = GetUuIdUtils.ReplaceUuId();
            qyReservation.setId(qyReservationId);
            qyReservation.setFsj(fsj);
            qyReservation.setFyzm(fyzm);
            qyReservation.setFyzmyxq(fyzmyxq);


            qyReservation.setFtjzt(OaCommonFlowConstant.TJZT_NO);
            qyReservationService.save(qyReservation);

            List<QyReservationSxlb> qyReservationSxlbList = qyReservationSxlbService.list(new LambdaQueryWrapper<QyReservationSxlb>()
                    .orderByAsc(QyReservationSxlb::getFxh));


            List<QyReservationSxlb> fjList = qyReservationSxlbList.stream().filter(f -> StringUtils.isBlank(f.getFfjid()))
                    .collect(Collectors.toList());

            qyReservationZxsxlbList = new ArrayList();

            for (QyReservationSxlb fj:fjList){
                QyReservationZxsxlb qyReservationZxsxlb = new QyReservationZxsxlb();
                BeanUtils.copyProperties(qyReservationZxsxlb,fj);
                qyReservationZxsxlb.setFyybid(qyReservationId);
                qyReservationZxsxlb.setId(GetUuIdUtils.ReplaceUuId());
                qyReservationZxsxlb.setFxzzt(OaCommonFlowConstant.XZZT_NO);
                qyReservationZxsxlbList.add(qyReservationZxsxlb);

                List<QyReservationSxlb> fjListToZjList = qyReservationSxlbList.stream()
                        .filter(f -> StringUtils.isNotBlank(f.getFfjid()) && fj.getId().equals(f.getFfjid()))
                        .collect(Collectors.toList());

                if (CollectionUtil.isNotEmpty(fjListToZjList)){
                    for (QyReservationSxlb zjList:fjListToZjList){
                        QyReservationZxsxlb qyReservationZxsxlbs = new QyReservationZxsxlb();
                        BeanUtils.copyProperties(qyReservationZxsxlbs,zjList);
                        qyReservationZxsxlbs.setFyybid(qyReservationId);
                        qyReservationZxsxlbs.setId(GetUuIdUtils.ReplaceUuId());
                        qyReservationZxsxlbs.setFxzzt(OaCommonFlowConstant.XZZT_NO);
                        qyReservationZxsxlbs.setFfjid(qyReservationZxsxlb.getId());
                        qyReservationZxsxlbList.add(qyReservationZxsxlbs);
                    }
                }
            }
            qyReservationZxsxlbService.saveBatch(qyReservationZxsxlbList);
        }else {
            qyReservation = qyReservationList.get(0);
            qyReservationZxsxlbList = qyReservationZxsxlbService.list(new LambdaQueryWrapper<QyReservationZxsxlb>()
                    .eq(QyReservationZxsxlb::getFyybid, qyReservation.getId())
                    .orderByAsc(QyReservationZxsxlb::getFxh));
        }
        return this.sxlbJg(qyReservation,qyReservationZxsxlbList);
    }




    /**
     * 预约登记
     *
     * */
    public Map yydj(String fsj,String fyzm) throws InvocationTargetException, IllegalAccessException {
        if (StringUtils.isBlank(fsj)){
            throw new BusinessException("未填写手机号，请重新填写");
        }
        if (StringUtils.isBlank(fyzm)){
            throw new BusinessException("验证码为空，请输入验证码");
        }
        //先判断验证码 和验证码有效期 匹配不上 直接抛出错误
        List<QyReservation> qyReservations = qyReservationService.list(new LambdaQueryWrapper<QyReservation>()
                .eq(QyReservation::getFsj, fsj).eq(QyReservation::getFtjzt, OaCommonFlowConstant.TJZT_NO)
                .eq(QyReservation::getFyzm,fyzm));
        //获取当前时间 加 10分钟 如果 大于 表里的验证码有效期 也直接抛出错误

        //先比对验证码, 如果查出为空 则直接抛出错误，然后在比对有效期是否过期 过期直接抛出错误
        if (CollectionUtils.isEmpty(qyReservations)){
            throw new BusinessException("验证码不正确,请重新输入");
        }else {
            QyReservation qyReservation = qyReservations.get(0);

            // 字符串类型的时间
            String strDateTime = qyReservation.getFyzmyxq();
            // 定义日期时间格式
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
            // 将字符串类型的时间解析为LocalDateTime对象
            LocalDateTime fyzmyxq = LocalDateTime.parse(strDateTime, formatter);

            // 获取当前时间
            LocalDateTime nowTime = LocalDateTime.now();

            // 比较两个时间的大小
            if (nowTime.isAfter(fyzmyxq)) {
                throw new BusinessException("验证码过期，请重新发送验证码");
            }
        }


        String qyReservationId = null;

        List<QyReservation> qyReservationList = qyReservationService.list(new LambdaQueryWrapper<QyReservation>()
                .eq(QyReservation::getFsj, fsj).eq(QyReservation::getFtjzt, OaCommonFlowConstant.TJZT_NO));

        QyReservation qyReservation = null;
        List<QyReservationZxsxlb> qyReservationZxsxlbList = null;
        //初始化
        if (CollectionUtils.isEmpty(qyReservationList)){
            qyReservation = new QyReservation();
            qyReservationId = GetUuIdUtils.ReplaceUuId();
            qyReservation.setId(qyReservationId);
            qyReservation.setFsj(fsj);
            qyReservation.setFsffsdx(OaCommonFlowConstant.NO);
            qyReservation.setFtjzt(OaCommonFlowConstant.TJZT_NO);
            qyReservationService.save(qyReservation);

            List<QyReservationSxlb> qyReservationSxlbList = qyReservationSxlbService.list(new LambdaQueryWrapper<QyReservationSxlb>()
                                                            .orderByAsc(QyReservationSxlb::getFxh));

            List<QyReservationSxlb> fjList = qyReservationSxlbList.stream().filter(f -> StringUtils.isBlank(f.getFfjid()))
                                            .collect(Collectors.toList());

            qyReservationZxsxlbList = new ArrayList();

            for (QyReservationSxlb fj:fjList){
                QyReservationZxsxlb qyReservationZxsxlb = new QyReservationZxsxlb();
                BeanUtils.copyProperties(qyReservationZxsxlb,fj);
                qyReservationZxsxlb.setFyybid(qyReservationId);
                qyReservationZxsxlb.setId(GetUuIdUtils.ReplaceUuId());
                qyReservationZxsxlb.setFxzzt(OaCommonFlowConstant.XZZT_NO);
                qyReservationZxsxlbList.add(qyReservationZxsxlb);

                List<QyReservationSxlb> fjListToZjList = qyReservationSxlbList.stream()
                                                        .filter(f -> StringUtils.isNotBlank(f.getFfjid()) && fj.getId().equals(f.getFfjid()))
                                                        .collect(Collectors.toList());

                if (CollectionUtil.isNotEmpty(fjListToZjList)){
                    for (QyReservationSxlb zjList:fjListToZjList){
                        QyReservationZxsxlb qyReservationZxsxlbs = new QyReservationZxsxlb();
                        BeanUtils.copyProperties(qyReservationZxsxlbs,zjList);
                        qyReservationZxsxlbs.setFyybid(qyReservationId);
                        qyReservationZxsxlbs.setId(GetUuIdUtils.ReplaceUuId());
                        qyReservationZxsxlbs.setFxzzt(OaCommonFlowConstant.XZZT_NO);
                        qyReservationZxsxlbs.setFfjid(qyReservationZxsxlb.getId());
                        qyReservationZxsxlbList.add(qyReservationZxsxlbs);
                    }
                }
            }
            qyReservationZxsxlbService.saveBatch(qyReservationZxsxlbList);
        }else {
             qyReservation = qyReservationList.get(0);
             qyReservationZxsxlbList = qyReservationZxsxlbService.list(new LambdaQueryWrapper<QyReservationZxsxlb>()
                    .eq(QyReservationZxsxlb::getFyybid, qyReservation.getId())
                    .orderByAsc(QyReservationZxsxlb::getFxh));
        }
        return this.sxlbJg(qyReservation,qyReservationZxsxlbList);
    }

    public Map yydj(String fsj) throws InvocationTargetException, IllegalAccessException {


        String qyReservationId = null;

        List<QyReservation> qyReservationList = qyReservationService.list(new LambdaQueryWrapper<QyReservation>()
                .eq(QyReservation::getFsj, fsj).eq(QyReservation::getFtjzt, OaCommonFlowConstant.TJZT_NO));

        QyReservation qyReservation = null;
        List<QyReservationZxsxlb> qyReservationZxsxlbList = null;
        //初始化
        if (CollectionUtils.isEmpty(qyReservationList)){
            qyReservation = new QyReservation();
            qyReservationId = GetUuIdUtils.ReplaceUuId();
            qyReservation.setId(qyReservationId);
            qyReservation.setFsj(fsj);

            qyReservation.setFtjzt(OaCommonFlowConstant.TJZT_NO);
            qyReservation.setFsffsdx(OaCommonFlowConstant.NO);
            qyReservationService.save(qyReservation);

            List<QyReservationSxlb> qyReservationSxlbList = qyReservationSxlbService.list(new LambdaQueryWrapper<QyReservationSxlb>()
                    .orderByAsc(QyReservationSxlb::getFxh));

            List<QyReservationSxlb> fjList = qyReservationSxlbList.stream().filter(f -> StringUtils.isBlank(f.getFfjid()))
                    .collect(Collectors.toList());

            qyReservationZxsxlbList = new ArrayList();

            for (QyReservationSxlb fj:fjList){
                QyReservationZxsxlb qyReservationZxsxlb = new QyReservationZxsxlb();
                BeanUtils.copyProperties(qyReservationZxsxlb,fj);
                qyReservationZxsxlb.setFyybid(qyReservationId);
                qyReservationZxsxlb.setId(GetUuIdUtils.ReplaceUuId());
                qyReservationZxsxlb.setFxzzt(OaCommonFlowConstant.XZZT_NO);
                qyReservationZxsxlbList.add(qyReservationZxsxlb);

                List<QyReservationSxlb> fjListToZjList = qyReservationSxlbList.stream()
                        .filter(f -> StringUtils.isNotBlank(f.getFfjid()) && fj.getId().equals(f.getFfjid()))
                        .collect(Collectors.toList());

                if (CollectionUtil.isNotEmpty(fjListToZjList)){
                    for (QyReservationSxlb zjList:fjListToZjList){
                        QyReservationZxsxlb qyReservationZxsxlbs = new QyReservationZxsxlb();
                        BeanUtils.copyProperties(qyReservationZxsxlbs,zjList);
                        qyReservationZxsxlbs.setFyybid(qyReservationId);
                        qyReservationZxsxlbs.setId(GetUuIdUtils.ReplaceUuId());
                        qyReservationZxsxlbs.setFxzzt(OaCommonFlowConstant.XZZT_NO);
                        qyReservationZxsxlbs.setFfjid(qyReservationZxsxlb.getId());
                        qyReservationZxsxlbList.add(qyReservationZxsxlbs);
                    }
                }
            }
            qyReservationZxsxlbService.saveBatch(qyReservationZxsxlbList);
        }else {
            qyReservation = qyReservationList.get(0);
            qyReservationZxsxlbList = qyReservationZxsxlbService.list(new LambdaQueryWrapper<QyReservationZxsxlb>()
                    .eq(QyReservationZxsxlb::getFyybid, qyReservation.getId())
                    .orderByAsc(QyReservationZxsxlb::getFxh));
        }
        return this.sxlbJg(qyReservation,qyReservationZxsxlbList);
    }

    //返回前端的事项类别的结构
    public Map sxlbJg(QyReservation qyReservation,List<QyReservationZxsxlb> qyReservationZxsxlbs){
        Map map = new HashMap();

        map.put("qyReservation",qyReservation);


        List<QyReservationZxsxlb> fjList = qyReservationZxsxlbs.stream().filter(f -> StringUtils.isBlank(f.getFfjid()))
                .collect(Collectors.toList());

        List<Map> lbMapList = new ArrayList();

        for (QyReservationZxsxlb fj:fjList){
            Map lbMap = new HashMap();
            lbMap.put("fj",fj);
            List<QyReservationZxsxlb> zjList = qyReservationZxsxlbs.stream()
                    .filter(f -> StringUtils.isNotBlank(f.getFfjid()) && fj.getId().equals(f.getFfjid()))
                    .collect(Collectors.toList());
            lbMap.put("zjList",zjList);
            lbMapList.add(lbMap);
        }
        map.put("lbMapList",lbMapList);
        return map;
    }

    //刷新主表
    public Map sxyyb(String yybId) {
        QyReservation qyReservationById = qyReservationService.getById(yybId);
        List<QyReservationZxsxlb> qyReservationZxsxlbList = qyReservationZxsxlbService.list(new LambdaQueryWrapper<QyReservationZxsxlb>()
                .eq(QyReservationZxsxlb::getFyybid, yybId)
                .orderByAsc(QyReservationZxsxlb::getFxh));

        return this.sxlbJg(qyReservationById, qyReservationZxsxlbList);
    }

    //更新主表
    public Result updateZb(HashMap<String,String> yyb) throws InvocationTargetException, IllegalAccessException {
        String yybId = yyb.get("id");
        QyReservation qyReservationById = qyReservationService.getById(yybId);
        ConvertUtils.register(new DateConvert(),Date.class);
        BeanUtils.populate(qyReservationById,yyb);
        boolean b = qyReservationService.updateById(qyReservationById);

        return Result.ok("更新成功");
    }

    //更新子表
    public Result updateJb(String id,String fxzzt) {
        QyReservationZxsxlb zxsxlbServiceById = qyReservationZxsxlbService.getById(id);


        //根据选中状态 查询父级id不为空的数据 将其父级状态 更新为选中
        if (StringUtils.isNotBlank(zxsxlbServiceById.getFfjid()) && fxzzt.equals(OaCommonFlowConstant.XZZT_YES)){
            List<QyReservationZxsxlb> fjZxsxlbsList = qyReservationZxsxlbService.list(new LambdaQueryWrapper<QyReservationZxsxlb>()
                    .eq(QyReservationZxsxlb::getId, zxsxlbServiceById.getFfjid()));

            if(CollectionUtils.isEmpty(fjZxsxlbsList)){
                throw new BusinessException("查询不到父级事项，请联系管理员");
            }

            String fjId = fjZxsxlbsList.get(0).getId();
            QyReservationZxsxlb fjZxsxlbs = qyReservationZxsxlbService.getById(fjId);
            fjZxsxlbs.setFxzzt(OaCommonFlowConstant.XZZT_YES);
            zxsxlbServiceById.setFxzzt(fxzzt);
            qyReservationZxsxlbService.updateById(zxsxlbServiceById);
            qyReservationZxsxlbService.updateById(fjZxsxlbs);
        }else if (StringUtils.isNotBlank(zxsxlbServiceById.getFfjid()) && fxzzt.equals(OaCommonFlowConstant.XZZT_NO)){
            List<QyReservationZxsxlb> fjZxsxlbsList = qyReservationZxsxlbService.list(new LambdaQueryWrapper<QyReservationZxsxlb>()
                    .eq(QyReservationZxsxlb::getId, zxsxlbServiceById.getFfjid()));

            if(CollectionUtils.isEmpty(fjZxsxlbsList)){
                throw new BusinessException("查询不到父级事项，请联系管理员");
            }
            String fjId = fjZxsxlbsList.get(0).getId();
            QyReservationZxsxlb fjZxsxlbs = qyReservationZxsxlbService.getById(fjId);
            fjZxsxlbs.setFxzzt(OaCommonFlowConstant.XZZT_NO);
            zxsxlbServiceById.setFxzzt(fxzzt);
            qyReservationZxsxlbService.updateById(zxsxlbServiceById);
            qyReservationZxsxlbService.updateById(fjZxsxlbs);
        }


        return Result.ok("更新成功");
    }

    //提交
    public Result tjNr(String yybId){
        QyReservation qyReservationServiceById = qyReservationService.getById(yybId);

        if (qyReservationServiceById.getFtjzt().equals(OaCommonFlowConstant.TJZT_YES)){
            throw new BusinessException("当前咨询预约表已经提交，请勿重复操作");
        }
        if (StringUtils.isNotBlank(qyReservationServiceById.getFlczt())){
            throw new BusinessException("当前审核已办理 请勿重复提交");
        }

        qyReservationServiceById.setFtjzt(OaCommonFlowConstant.TJZT_YES); //通知状态
        qyReservationServiceById.setFclzt(OaCommonFlowConstant.CLZT_NO); //处理状态
        qyReservationServiceById.setFqyhfzt(OaCommonFlowConstant.HFZT_NO); //回复状态
        //新增一个字段，查询父id为空 并且选中状态为1的名字 更新到子表中
        String fmc = null;
        List<QyReservationZxsxlb> qyReservationZxsxlbs = qyReservationZxsxlbService.list(new LambdaQueryWrapper<QyReservationZxsxlb>()
                                                                                    .eq(QyReservationZxsxlb::getFyybid, yybId)
                                                                                    .isNull(QyReservationZxsxlb :: getFfjid)
                                                                                    .eq(QyReservationZxsxlb :: getFxzzt, OaCommonFlowConstant.XZZT_YES));
        if (CollectionUtils.isNotEmpty(qyReservationZxsxlbs)){
            for (QyReservationZxsxlb zxsxlb :qyReservationZxsxlbs){
                 fmc = zxsxlb.getFmc();
            }
        }else {
            throw new BusinessException("没有选择主类咨询事项");
        }
        qyReservationServiceById.setFzxsx(fmc);
        qyReservationService.updateById(qyReservationServiceById);
        HttpResult<?> httpResult = newQyResevvationFlowController.initBzFlow(qyReservationServiceById);
        return Result.ok(httpResult);
    }

    //退回
    public Result thNr(String yybId){
        QyReservation qyReservationServiceById = qyReservationService.getById(yybId);

        //退回时将 流程提交到 综合科审核


        if (qyReservationServiceById.getFclzt().equals(OaCommonFlowConstant.CLZT_LOAD)){
            throw new BusinessException("当前咨询申请已在处理中，无法返回修改。请等待");
        }


        //如果退回将 oa流程集成表也一起删除
        List<OaProcessBusiness> processBusinesses = oaProcessBusinessService.list(new LambdaQueryWrapper<OaProcessBusiness>()
                .eq(OaProcessBusiness::getFpid, yybId));

        if (CollectionUtils.isNotEmpty(processBusinesses)){
            String id = processBusinesses.get(0).getId();
            oaProcessBusinessService.removeById(id);
        }

        qyReservationServiceById.setFtjzt(OaCommonFlowConstant.TJZT_NO);
        qyReservationService.updateById(qyReservationServiceById);

        return Result.ok("退回成功");
    }


    //验证类别
    public Result yzLb(String yybId){
        List<QyReservationZxsxlb> qyReservationZxsxlbs = qyReservationZxsxlbService.list(new LambdaQueryWrapper<QyReservationZxsxlb>()
                                                                                            .eq(QyReservationZxsxlb::getFyybid, yybId).eq(QyReservationZxsxlb::getFxzzt, OaCommonFlowConstant.XZZT_YES));

        if (CollectionUtils.isEmpty(qyReservationZxsxlbs)){
            throw new BusinessException("咨询事项类别不能为空");
        }else {
            return Result.ok("success");
        }

    }

    //个人咨询预约列表
    public List zxyyList(String fsj,String yzm){
        List<QyReservation> qyReservations = qyReservationService.list(new LambdaQueryWrapper<QyReservation>()
                .eq(QyReservation::getFsj, fsj)
                 .eq(QyReservation::getFtjzt, "1")
                .or()
                .ne(QyReservation::getFlczt, OaCommonFlowConstant.FLOW_LCJS)
                .isNull(QyReservation::getFlczt));

        if (CollectionUtils.isNotEmpty(qyReservations)){
            for (QyReservation qyReservation : qyReservations){
                qyReservation.setFyzm(yzm);
                qyReservationService.updateById(qyReservation);
            }
        }

        return qyReservations;
    }

    //预约可选日期查询
    public List yyrq(){
        //判断是否为周四前 如果是 返回 下周二 和 下下周二 的日期
        Date date1 = new Date();
        Integer weekOfDate = getWeekOfDate(date1);

        LocalDate nextTuesday = null;
        LocalDate twoTuesday =null;

        if (weekOfDate != OaCommonFlowConstant.WEEKDAY_ZR && weekOfDate <= OaCommonFlowConstant.WEEKDAY_ZSI){

            LocalDate date = LocalDate.now();

            // 计算下周二的日期
             nextTuesday = date.plus(7, ChronoUnit.DAYS)
                    .with(DayOfWeek.TUESDAY);
            // 计算下下周二的日期
             twoTuesday = date.plus(14, ChronoUnit.DAYS)
                    .with(DayOfWeek.TUESDAY);


        }else {
            //如果不是 返回下下周二 和 下下下周二 的 日期
            LocalDate date = LocalDate.now();

            // 计算下周二的日期
             nextTuesday = date.plus(14, ChronoUnit.DAYS)
                    .with(DayOfWeek.TUESDAY);
            // 计算下下周二的日期
             twoTuesday = date.plus(21, ChronoUnit.DAYS)
                    .with(DayOfWeek.TUESDAY);
        }
        List rqList = new ArrayList();
        rqList.add(nextTuesday);
        rqList.add(twoTuesday);

        return rqList;
    }





    public Integer getWeekOfDate(Date date) {
        //周日 周一 周二 周三 周四 周五 周六

        Integer[] weekDays = {OaCommonFlowConstant.WEEKDAY_ZR, OaCommonFlowConstant.WEEKDAY_ZY,
                            OaCommonFlowConstant.WEEKDAY_ZE, OaCommonFlowConstant.WEEKDAY_ZS,
                            OaCommonFlowConstant.WEEKDAY_ZSI, OaCommonFlowConstant.WEEKDAY_ZW,
                            OaCommonFlowConstant.WEEKDAY_ZL};
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
        if (w < 0)
            w = 0;
        return weekDays[w];
    }


}
